package jmu.edu.cn.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import jmu.edu.cn.domain.Admin;
import jmu.edu.cn.utils.DBUtils;

public class AdminDaoJDBCImpl implements AdminDao {
	private static final String GET_ADMIN = "select * from user_tbl where user_no =?";

	@Override
	public Admin getAdminByNo(String adminNo) {
		DBUtils utils = DBUtils.getInstance();
		Connection conn = null;
		PreparedStatement psmt = null;
		ResultSet rs = null;
		Admin admin = null;

		try {
			admin = new Admin();
			conn = utils.getConn();
			psmt = conn.prepareStatement(GET_ADMIN);
			psmt.setString(1, adminNo);
			rs = psmt.executeQuery();
			if (rs.next()) {
				admin.setUserNo(rs.getString(1));
				admin.setUserPasswd(rs.getString(2));
				admin.setUserName(rs.getString(3));
				admin.setUserDescription(rs.getString(4));
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			utils.releaseAll(conn, psmt, rs);
		}
		return admin;
	}
}
